import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

// 页面刷新时，重新赋值token
//token： 5188c5187d48df67b0c8953813791f25ed4e367c
// if (window.localStorage.getItem('token')) {
//   store.commit(types.LOGIN, window.localStorage.getItem('token'))
// }


// 路由配置
export default new Router({
  routes: [
    {
      path: '/login',
      name: '登录',
      component: resolve => require(['@/components/page/Login.vue'], resolve)
    },
    {
      path: '/home',
      component: resolve => require(['@/components/page/Home.vue'], resolve),
      meta: { ParentNmame: '用户档案' },
      children: [
      //  用户档案
      	{
      		path: '/user/personal',
      		name: '用户信息',
      		component: resolve => require(['@/components/page/user/Personal.vue'],resolve),
      		meta: { ParentNmame: '用户档案' }
      	},
      	{
      		path: '/user/personal/edit/:id',
      		name: '用户信息编辑',
      		component: resolve => require(['@/components/page/user/EditUser.vue'],resolve),
      		meta: { ParentNmame: '用户档案' }
      	},
      	//  用户信息  数据监测中的 血糖  血压 体重  路由
      	{
      		path: '/user/monitor/bloodsugar/edit/:id',
      		name: '用户信息编辑',
      		component: resolve => require(['@/components/page/user/component/datamonitor/BloodSuMonitor.vue'],resolve),
      		meta: { ParentNmame: '用户档案' }
      	},
      	{
      		path: '/user/monitor/bloodpre/edit/:id',
      		name: '用户信息编辑',
      		component: resolve => require(['@/components/page/user/component/datamonitor/BloodPreMonitor.vue'],resolve),
      		meta: { ParentNmame: '用户档案' }
      	},
      	{
      		path: '/user/monitor/weight/edit/:id',
      		name: '用户信息编辑',
      		component: resolve => require(['@/components/page/user/component/datamonitor/WeightMonitor.vue'],resolve),
      		meta: { ParentNmame: '用户档案' }
      	},
      	//  用户监测
      	{
      		path: '/customer/bloodsugar',
      		name: '用户血糖',
      		component: resolve => require(['../components/page/customer/Bloodsugar.vue'],resolve),
      		meta: { ParentNmame: '用户监测' }
      	},
      	{
      		path: '/customer/bloodpressure',
      		name: '用户血压',
      		component: resolve => require(['../components/page/customer/Bloodpressure.vue'],resolve),
      		meta: { ParentNmame: '用户监测' }
      	},
      	{
      		path: '/customer/weight',
      		name: '用户体重',
      		component: resolve => require(['../components/page/customer/Weight.vue'],resolve),
      		meta: { ParentNmame: '用户监测' }
      	},
      	//  病历管理
      	{
      		path: '/case/info',
      		name: '病历信息',
      		component: resolve => require(['../components/page/case/Case.vue'],resolve),
      		meta: { ParentNmame: '病历管理 ' }
      	},
      	{
      		path: '/case/info/edit/:id',
      		name: '病历信息编辑',
      		component: resolve => require(['../components/page/case/EditCase.vue'],resolve),
      		meta: { ParentNmame: '病历管理 ' }
      	},
      	// 改善管理
      	{
      		path: '/improve/info',
      		name: '改善信息',
      		component: resolve => require(['../components/page/improve/Improve.vue'],resolve),
      		meta: { ParentNmame: '改善管理 ' }
      	},
      	{
      		path: '/improve/info/edit/:id',
      		name: '改善信息编辑',
      		component: resolve => require(['../components/page/improve/EditImprove.vue'],resolve),
      		meta: { ParentNmame: '改善管理 ' }
      	},
      	{
      		path: '/improve/form/:id',
      		name: '改善信息编辑',
      		component: resolve => require(['../components/page/common/improveCom/ImproveForm.vue'],resolve),
      		meta: { ParentNmame: '改善管理 ' }
      	},
      	{
      		path: '/consultation/index',
      		name: '在线咨询',
      		component: resolve => require(['../components/page/consultation/consultation.vue'],resolve),
      		meta: { ParentNmame: '在线咨询 ' }
      	},
      	{
      		path: '/consultation/editReply/:id',
      		name: '在线咨询',
      		component: resolve => require(['../components/page/consultation/EditReply.vue'],resolve),
      		meta: { ParentNmame: '在线咨询' }
      	}
      ]
    },
    // 路由重定向
    {
      path: '/',
      redirect: '/login'
    },
    { 
    	path: "*", 
    	redirect: '/home' 
    }
  ]
})

// 路由拦截
// router.beforeEach((to, from, next) => {
//   if (to.matched.some(r => r.meta.requireAuth)) {
//       if (store.state.token) {
//           next();
//       }
//       else {
//           next({
//               path: '/login',
//               query: {redirect: to.fullPath}
//           })
//       }
//   }
//   else {
//       next();
//   }
// })
